#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int T, n, m, l, v;
int D[N], V[N], A[N], p[N];
int main()
{
    freopen("detect.in","r", stdin);
    freopen("detect.out", "w", stdout);
    cin.tie(0);
    cin>>T;
    for (int g=1; g<=T; ++g)
    {
        cin>>n>>m>>l>>v;
        for (int i=1; i<=n; ++i)
        {
            cin>>D[i]>>V[i]>>A[i];
        }
        for (int i=1; i<=m; ++i)
        {
            int temp;
            cin>>temp;
            p[temp]=1;
        }
        int ans=0;
        for (int i=1; i<=n; ++i)
        {
            if (V[i]>v)
            {
                for (int j=D[i]; j<=l; ++j)
                {
                    if (p[j]==1)
                    {
                        ++ans;
                        break;
                    }
                }
            }
        }
        cout<<ans<<' ';
        if (ans==0) cout<<m<<'\n';
        else cout<<m-1<<'\n';
        for (int i=0; i<N; ++i)
        {
            D[i]=0; V[i]=0; p[i]=0; A[i]=0;
        }
    }
    return 0;
}
